package com.jn.news.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.jn.news.R;
import com.jn.news.model.NewsDto;
import com.jn.news.ui.NewsDetailActivity;
import com.jn.news.utils.Constant;

;


//订单列表适配器
public class TianxingNewsAdapter extends BaseAdapter<NewsDto, TianxingNewsAdapter.MyViewHolder> {


    private OnItemClickListener onItemClickListener;

    public TianxingNewsAdapter(Context context) {
        super(context);
    }


    @Override
    protected int onBindLayout() {
        return R.layout.item_news2;
    }

    @Override
    protected MyViewHolder onCreateHolder(View view) {
        return new MyViewHolder(view);
    }



    @Override
    protected void onBindData(MyViewHolder holder, NewsDto newsDto, int position) {
        //标题
        holder.tvTitle.setText(newsDto.getTitle());
        //时间
        holder.tvTime.setText(newsDto.getCtime());
        //来源
        holder.tvSource.setText(newsDto.getSource());
        Glide.with(mContext).load(newsDto.getPicUrl()).placeholder(R.mipmap.ic_no_picture).into(holder.ivPic);
        holder.llNews.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, NewsDetailActivity.class);
                intent.putExtra(Constant.NEWS_DETAIL,newsDto);
                mContext.startActivity(intent);
            }
        });
    }


    public interface OnItemClickListener{
        void onItemClick(int position);


    }
    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.onItemClickListener = onItemClickListener;
    }
    class MyViewHolder extends RecyclerView.ViewHolder {


        LinearLayout llNews;
        TextView tvTitle;
        TextView tvTime;
        TextView tvSource;
        ImageView ivPic;


        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            tvTitle = itemView.findViewById(R.id.tv_title);
            tvTime = itemView.findViewById(R.id.tv_time);
            ivPic = itemView.findViewById(R.id.iv_pic);
            llNews = itemView.findViewById(R.id.ll_news);
            tvSource = itemView.findViewById(R.id.tv_source);
        }
    }
}
